package com.atguigu.gulimall.auth.test;

import org.junit.Test;

/**
 * @author wfjytd
 * @create 2022-01-16 21:29
 */
public class Step {

    @Test
    public void test1(){
        long start = System.currentTimeMillis();
        int f = loop(100);
        long end = System.currentTimeMillis();
        System.out.println(f + "==>" + (end-start));
    }


    public int f(int n){
        if (n < 1){
            throw new IllegalArgumentException(n + "不能小于1");
        }
        if (n ==1 || n == 2){
            return n;
        }
        return f(n -2 ) + f(n -1);
    }

    public int loop(int n){
        if (n < 1){
            throw new IllegalArgumentException(n + "不能小于1");
        }
        if (n ==1 || n == 2){
            return n;
        }
        int one = 2;
        int two = 1;
        int sum =0;
        for (int i = 3; i <= n; i++) {
            //最后跨2步+最后跨1步的走法
            sum = two + one;
            two = one;
            one = sum;
        }
        return sum;
    }

}
